using System;
using FireStarter.CodeGeneration;
using FireStarter.CodeGeneration.Generator;
using NUnit.Framework;

namespace FireStarter.Test.CodeGeneration.Parser
{
    public class ParserTestUtils
    {
        public static void AssertExpressionIsLiteral(string content, TemplateExpression expression)
        {
            Assert.IsNotNull(expression);
            Assert.IsInstanceOf(typeof (LiteralExpression), expression);
            var literalExpression = (LiteralExpression) expression;
            Assert.AreEqual(content, literalExpression.Literal);
        }

        public static void AssertExpressionIsValue(string propertyName, TemplateExpression expression)
        {
            Assert.IsNotNull(expression);
            Assert.IsInstanceOf(typeof(ValueExpression), expression);
            ValueExpression valueExpression = (ValueExpression)expression;
            Assert.AreEqual(propertyName, valueExpression.PropertyName);
        }

        public static void AssertExpressionIsForEach(string propertyName, TemplateExpression expression, out ForEachExpression forEachExpression)
        {
            Assert.IsNotNull(expression);
            Assert.IsInstanceOf(typeof(ForEachExpression), expression);
            forEachExpression = (ForEachExpression)expression;
            Assert.AreEqual(propertyName, forEachExpression.CollectionName);
        }

        public static void AssertExpressionIsForEach(string propertyName, TemplateExpression expression)
        {
            ForEachExpression forEachExpression;
            AssertExpressionIsForEach(propertyName, expression, out forEachExpression);
        }

        public static void AssertExpressionIsIf(string propertyName, TemplateExpression expression, out IfExpression ifExpression)
        {
            Assert.IsNotNull(expression);
            Assert.IsInstanceOf(typeof(IfExpression), expression);
            ifExpression = (IfExpression)expression;
            Assert.AreEqual(propertyName, ifExpression.PropertyName);
        }

        public static void AssertExpressionIsComment(TemplateExpression expression)
        {
            Assert.IsNotNull(expression);
            Assert.IsInstanceOf(typeof(CommentExpression), expression);
        }

        public static void AssertExpressionIsInclude(TemplateExpression expression) {
            Assert.IsNotNull(expression);
            Assert.IsInstanceOf(typeof(IncludeExpression), expression);
        }
    }
}